package com.ruoyi.web.controller.supermarket;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.supermarket.domain.Returns;
import com.ruoyi.supermarket.service.IReturnsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 退货管理Controller
 *
 * @author wzy
 * @date 2024-07-22
 */
@RestController
@RequestMapping("/returns/returns")
public class ReturnsController extends BaseController
{
    @Autowired
    private IReturnsService returnsService;

    /**
     * 查询退货管理列表
     */
//    @PreAuthorize("@ss.hasPermi('returns:returns:list')")
    @GetMapping("/list")
    public TableDataInfo list(Returns returns)
    {
        startPage();
        List<Returns> list = returnsService.selectReturnsList(returns);
        return getDataTable(list);
    }

    /**
     * 导出退货管理列表
     */
    @PreAuthorize("@ss.hasPermi('returns:returns:export')")
    @Log(title = "退货管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Returns returns)
    {
        List<Returns> list = returnsService.selectReturnsList(returns);
        ExcelUtil<Returns> util = new ExcelUtil<Returns>(Returns.class);
        util.exportExcel(response, list, "退货管理数据");
    }

    /**
     * 获取退货管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('returns:returns:query')")
    @GetMapping(value = "/{rid}")
    public AjaxResult getInfo(@PathVariable("rid") Long rid)
    {
        return success(returnsService.selectReturnsByRid(rid));
    }

    /**
     * 新增退货管理
     */
    @PreAuthorize("@ss.hasPermi('returns:returns:add')")
    @Log(title = "退货管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Returns returns)
    {
        return toAjax(returnsService.insertReturns(returns));
    }

    /**
     * 修改退货管理
     */
    @PreAuthorize("@ss.hasPermi('returns:returns:edit')")
    @Log(title = "退货管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Returns returns)
    {
        return toAjax(returnsService.updateReturns(returns));
    }

    /**
     * 删除退货管理
     */
    @PreAuthorize("@ss.hasPermi('returns:returns:remove')")
    @Log(title = "退货管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rids}")
    public AjaxResult remove(@PathVariable Long[] rids)
    {
        return toAjax(returnsService.deleteReturnsByRids(rids));
    }

    /**
     * 向前端传递每种商品的名称和退货数量
     */
    //@PreAuthorize("@ss.hasPermi('returns:returns:getReturnsInfo')")
    @GetMapping(value = "/getReturnsInfo")
    public AjaxResult getReturnsInfo()
    {
        return success(returnsService.getReturnsInfo());
    }


}
